package com.scvtc.service.teacher.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.scvtc.domain.ResResult;
import com.scvtc.domain.dto.teacher.social.TeacherSocialServiceDto;
import com.scvtc.domain.entity.teacher.TeacherSocialService;
import com.scvtc.domain.vo.PageVo;
import com.scvtc.domain.vo.teacher.social.TeacherSocialServiceVo;
import com.scvtc.mapper.teacher.TeacherSocialServiceMapper;
import com.scvtc.service.teacher.TeacherSocialServiceService;
import com.scvtc.utils.BeanCopyUtils;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * 教师社会服务(TeacherSocialService)表服务实现类
 *
 * @author yiFei
 * @since 2022-06-02 16:17:10
 */
@Service("teacherSocialServiceService")
public class TeacherSocialServiceServiceImpl extends ServiceImpl<TeacherSocialServiceMapper, TeacherSocialService> implements TeacherSocialServiceService {
    /**
     * 查询教师服务信息
     *
     * @param current
     * @param size
     * @param teacherSocialServiceVo
     * @return
     */
    @Override
    public ResResult<PageVo<List<TeacherSocialServiceVo>>> getAllTeacherSocialService(Long current, Long size, TeacherSocialServiceVo teacherSocialServiceVo) {
        // 分页查询
        Page<TeacherSocialService> page = getBaseMapper().getAllTeacherSocialService(new Page<TeacherSocialService>(current, size), teacherSocialServiceVo);
        // 拷贝bean
        List<TeacherSocialServiceVo> teacherSocialServiceVos = BeanCopyUtils.copyBean(page.getRecords(), TeacherSocialServiceVo.class);
        // 统一返回
        return ResResult.noMsgSuccess(new PageVo<>(teacherSocialServiceVos, page.getTotal()));
    }

    /**
     * 增加教师服务信息
     *
     * @param teacherSocialServiceDto
     * @return
     */
    @Override
    public ResResult<?> addTeacherSocialService(TeacherSocialServiceDto teacherSocialServiceDto) {
        // 如果考虑后端安全性需要判断教工号是否存在 (代码可参考学生获奖表)
        TeacherSocialService teacherSocialService = BeanCopyUtils.copyBean(teacherSocialServiceDto, TeacherSocialService.class);
        // 判断是否保护成功
        if (save(teacherSocialService)) {
            return ResResult.success(teacherSocialService.getId());
        }
        return ResResult.fail();
    }

    /**
     * 修改教师服务信息
     *
     * @param teacherSocialServiceDto
     * @return
     */
    @Override
    public ResResult<?> updateTeacherSocialService(TeacherSocialServiceDto teacherSocialServiceDto) {
        // 如果考虑后端安全性需要判断教工号是否存在 (代码可参考学生获奖表)
        TeacherSocialService teacherSocialService = BeanCopyUtils.copyBean(teacherSocialServiceDto, TeacherSocialService.class);
        // 判断是否修改成功
        if (updateById(teacherSocialService)) {
            return ResResult.success();
        }
        return ResResult.fail();
    }

    /**
     * 删除单个教师服务信息
     *
     * @param id
     * @return
     */
    @Override
    public ResResult<?> deleteTeacherSocialService(Long id) {
        // 判断是否删除成功
        if (removeById(id)) {
            return ResResult.success();
        }
        return ResResult.fail();
    }

    /**
     * 删除多个教师服务信息
     *
     * @param ids
     * @return
     */
    @Override
    public ResResult<?> deleteMultipleTeacherSocialService(Long[] ids) {
        // 判断删除多个是否成功
        if (removeByIds(Arrays.asList(ids))) {
            return ResResult.success();
        }
        return ResResult.fail();
    }
}

